package com.example.autopia.view.ViewHolders.News

import android.view.LayoutInflater
import androidx.lifecycle.LifecycleOwner
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.example.autopia.databinding.ViewholderNewsActionBinding
import com.example.autopia.databinding.ViewholderNewsHotnewsBinding
import com.example.autopia.model.Item.HotNews
import com.example.autopia.model.Item.News
import com.example.autopia.model.Repositories.HotNewsRepository
import com.example.autopia.model.Repositories.TestRepository
import com.example.autopia.view.Adapters.HotNewsAdapter
import com.example.autopia.view.Listeners.HotNewsListener

class HotNewsViewHolder (private val binding: ViewholderNewsHotnewsBinding,private val inflater: LayoutInflater) :
    RecyclerView.ViewHolder(binding.root) {

    private lateinit var adapter: HotNewsAdapter
    private val hotnewsRepository = HotNewsRepository()
    private val lifecycleOwner by lazy{
        binding.root.context as? LifecycleOwner
    }

    fun bind(news: News){
        adapter = HotNewsAdapter()
        binding.rvHotNews.adapter = adapter
        val items = hotnewsRepository.getAllItems()
        adapter.setData(TestRepository.getHotNews())
        lifecycleOwner?.let {
            items.observe(it){
                adapter.setData(it)
            }
        }

        adapter.attachListener(object : HotNewsListener{
            override fun onNewsClick(hotNews: HotNews) {
               //Переход на новый
            }
        })
    }
}